package com.jn.dagger.views;

import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.jn.dagger.R;
import com.jn.dagger.application.MyApplication;
import com.jn.dagger.base.BaseActivity;
import com.jn.dagger.database.CourseDBHelper;
import com.jn.dagger.database.DBHelper;
import com.jn.dagger.entity.Course;
import com.jn.dagger.entity.Student;
import com.jn.dagger.module.DBModule;
import com.jn.dagger.module.StudentModule;
import com.jn.dagger.utils.SpUtils;

import java.util.List;

import jakarta.inject.Inject;

public class MainActivity extends BaseActivity implements View.OnClickListener {

    private Button mText;

    @Inject
    public Student mStudent1;

    @Inject
    public Student mStudent2;

    @Inject
    public DBHelper mDBHelper;


    @Inject
    public Course mCourse1 ;
    @Inject
    public Course mCourse2 ;
    @Inject
    public CourseDBHelper courseDBHelper ;

    @Override
    public int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    public void init() {
        mText = findViewById(R.id.m_text);
        mText.setOnClickListener(this);
        /*DaggerAllComponent
                .builder()
                .studentModule(new StudentModule())
                .dBModule(new DBModule(this))
                .build()
                .injectMainActivity(this);*/
        ((MyApplication)getApplication()).getAllComponent().injectMainActivity(this);
        Log.d("asdf", "Main mStudent1 === " + mStudent1.hashCode());
        Log.d("asdf", "Main mStudent2 === " + mStudent2.hashCode());
        mStudent1.setStudent_code("22");
        mStudent1.setStudent_id(1);
        mStudent1.setStudent_name("阿衰");
        mStudent1.setUsername("abcdef");
        mStudent1.setPassword("123456");
        mStudent1.setClass_name("2024");
        Log.d("asdf", "Main mDBHelper === " + mDBHelper.hashCode());
        mDBHelper.insertStudent(mStudent1);

        mCourse1.setCourse_id(1);
        mCourse1.setCourse_name("数电");
        mCourse1.setCourse_time(48);
        mCourse1.setTeacher("yaya");
        mCourse1.setClassroom("F405");
        courseDBHelper.insertCourse(mCourse1);

        List<Student> studentList = mDBHelper.selectAllStudent();
        SpUtils.getInstance(this).putList("students" , studentList);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.m_text){
            Intent intent = new Intent(MainActivity.this, InfoActivity.class);
            startActivity(intent);
        }
    }
}